﻿//
// Copyright (c) 2024 BPer
//
#include "bperRecAudioCaptureHandle.h"
#if BPer_OS_WIN
#include <strmif.h>


BPerRecAudioCaptureHandle::BPerRecAudioCaptureHandle(BPerAVInfo* avinfo):BPerAudioCaptureHandle(avinfo)
{
	readStart=0;

    if (avinfo->audio.enableMono) {
		m_len=320*2;
	} else {
		m_len = 1024*4;
	}
    if(avinfo->audio.sample==48000) m_len=960*6;
	m_buf=new uint8_t[m_len];

	m_aec=NULL;

}
BPerRecAudioCaptureHandle::~BPerRecAudioCaptureHandle(void)
{

	if(m_buf) delete[] m_buf;
	m_buf=NULL;
}


   STDMETHODIMP_(ULONG) BPerRecAudioCaptureHandle::AddRef() { return 1; }
   STDMETHODIMP_(ULONG) BPerRecAudioCaptureHandle::Release() { return 2; }

    STDMETHODIMP BPerRecAudioCaptureHandle::QueryInterface(REFIID riid, void **ppvObject)
    {

		if (NULL == ppvObject) return E_POINTER;
        if (riid == __uuidof(IUnknown))
        {
            *ppvObject = static_cast<IUnknown*>(this);
             return S_OK;
        }
        if (riid == IID_ISampleGrabber)
        {
            *ppvObject = static_cast<ISampleGrabberCB*>(this);
             return S_OK;
        }
        return E_NOTIMPL;
    }

    STDMETHODIMP BPerRecAudioCaptureHandle::SampleCB(double Time, IMediaSample *pSample)
    {

        return E_NOTIMPL;
    }

    STDMETHODIMP BPerRecAudioCaptureHandle::BufferCB(double Time, BYTE *pBuffer, long BufferLen)
    {

    	memset(m_buf,0,m_len);  
        putBuffer2(pBuffer,BufferLen);


	return E_NOTIMPL;
    }


#endif
